/*
 * main.cpp
 * 
 * Chat Server 主程序
 * 使用 BaseServer 框架 - 展示框架的强大功能
 * 
 * 阶段4：Chat Server 实战
 */

#include "servers/chat/ChatServer.h"
#include "common/config/ServerConfig.h"

#include <muduo/base/Logging.h>
#include <iostream>

int main(int argc, char* argv[]) {
    // 设置日志级别
    muduo::Logger::setLogLevel(muduo::Logger::INFO);
    
    // 加载配置文件
    std::string configFile = "config/chat.json";
    if (argc > 1) {
        configFile = argv[1];
    }
    
    framework::ServerConfig config;
    if (!config.loadFromFile(configFile)) {
        LOG_FATAL << "Failed to load config from: " << configFile;
        return -1;
    }
    
    // 创建并运行聊天服务器
    servers::ChatServer server(config);
    
    LOG_INFO << "========================================";
    LOG_INFO << "  Chat Server - BaseServer Framework";
    LOG_INFO << "  Stage 4: Chat Server Implementation";
    LOG_INFO << "========================================";
    LOG_INFO << "Server Name: " << config.serverName;
    LOG_INFO << "Listen: " << config.network.ip << ":" << config.network.port;
    LOG_INFO << "IO Threads: " << config.network.threadNum;
    LOG_INFO << "========================================";
    
    return server.run();  // 一行启动！强大的框架！
}

